
import neko.io.Process;


class Utils {
	
	
	private static var currentSeedNumber:Int = 0;
	private static var haxelibDirs:Hash<Array<String>> = new Hash();
	
	
	public static function getHaxelib (library:String):Array<String> {
		if (haxelibDirs.exists(library))
			return haxelibDirs.get(library).copy();
		
		var proc = new Process ("haxelib", ["path", library ]);
		var results = [];
		
		try {
			
			while (true) {
				
				var line = proc.stdout.readLine ();
				
				if (line.substr (0,1) != "-") {
					
					results.push(line);
					
				}
				
			}
			
		} catch (e:Dynamic) { };
		
		proc.close();
		
		//trace("Found " + haxelib + " at " + srcDir );
		
		if (results.length == 0) {
			
			throw ("Could not find haxelib path  " + library + " - perhaps you need to install it?");
			
		}
		
		haxelibDirs.set(library, results);
		return results.copy();
		
	}
	
	
	public static function getUniqueID ():String {
		
		return StringTools.hex (currentSeedNumber++, 8);
		
   }
	
	
}
